package service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import play.db.jpa.JPA;

import models.Offer;
import models.Service;
import models.Tag;
import models.User;

public class RecommendationManager 
{
	public List<Service> RecommendServices(User user) throws IOException{
		if (user == null) return null;
			
		List<Service> services = new ArrayList<Service>();
		
		String userInterestsCombined = "";
		for (Tag interest : user.interests) {
			userInterestsCombined = userInterestsCombined + " " + interest.name;
		}
		
		List<Long> excludedUsers = new ArrayList<Long>();
		excludedUsers.add(user.id);
		
		SearchManager searchManager = new SearchManager();
	 	services = searchManager.SearchServices(userInterestsCombined, excludedUsers);
	 	
	 	// filter sessions.
	 	List<Service> filteredServices = new ArrayList<Service>();
	 	for (Service service : services) {
	 		Service service2 = Service.findById(service.id);
	 		if (null == service2.parent) {
	 			filteredServices.add(service2);
	 		}
	 	}
	 	
		return filteredServices;
	}
	
}
